<?php

namespace app\services;

use plugin\admin\app\model\Area;

class AreaService
{
    public static function getAreas($parentId = 0)
    {
        return Area::where('area_parent_id', $parentId)->get()->toArray();
    }

    public static function cities()
    {
        $query = Area::select(['id', 'letter', 'area_name'])->where('area_deep', 2);

        $areas = $query->get()->toArray();

        $data = [];

        for ($i=65; $i<=90; $i++) {
            $data[chr($i)] = [];
        }

        foreach ($areas as $key=>$area) {
            $data[$area['letter']][] = $area;
        }

        return $data;
    }
}